package com.lyz.dataStructure.LeetCode;/**
 * @Author:759057893@qq.com Lyz
 * @Date: ${Date} 20:01
 * @Description:
 **/

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

/**
 *@Author:759057893@qq.com Lyz
 *@Date: 2019/4/18 20:01
 *@Description:
 **/

/*
输入: nums = [-1,0,3,5,9,12], target = 9
输出: 4
解释: 9 出现在 nums 中并且下标为 4

输入: nums = [-1,0,3,5,9,12], target = 2
输出: -1
解释: 2 不存在 nums 中因此返回 -1
 */
public class Test {

    public static void main(String[] args) {

        Scanner in  = new Scanner(System.in);
        while(in.hasNext()){
            String s = in.nextLine();
            String[] s1 = s.split(",");
            int[] arr = new int[s1.length];
            for(int i =0;i<arr.length;i++){
                arr[i] = Integer.parseInt(s1[i]);
            }
            int target = in.nextInt();
            System.out.println(search(arr,target));
        }

    }

    public static int search(int[] nums, int target) {

        int left=0;
        int right =nums.length-1;
        int mid ;
        while(left<=right){
            mid = (left+right)/2;
            if(target==nums[mid]){
                return mid;
            }else if(target>nums[mid]){
                left =mid+1;
            }else{
                right = mid -1;
            }
        }
        return -1;
    }
}
